package com.atguigu.gmall.scheduled.jdk;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

public class ScheduledDemo {

    public static void main(String[] args) {
        System.out.println("定时任务初始时间：" + System.currentTimeMillis());

        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        scheduledExecutorService.scheduleAtFixedRate(() -> {
            System.out.println("这是通过定时任务线程池初始化了一个定时任务：" + System.currentTimeMillis());
        }, 5, 10, TimeUnit.SECONDS);


//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//                System.out.println("这是通过定时器初始化了一个定时任务：" + System.currentTimeMillis());
//            }
//        }, 5000, 10000);
    }
}
